<?php

include "jsonclass.php";

header('Content-type: application/json');

$data = (@$_GET["jsondata"])?$_GET["jsondata"]:"";

$decodedData = base64_decode($data);

$decodedJsonData = json_decode($decodedData);

print_r($decodedJsonData);

establishSQLDatabaseConnection();

#loading parameters
$itemList = $decodedJsonData -> items;

$kpiList = $decodedJsonData -> kpis;

$userID = $decodedJsonData -> userid;

$isMetric = $decodedJsonData -> ismetric;

$className = $decodedJsonData -> classname;

$norm = $decodedJsonData -> norm;

#initialize class
$obResponse = new Response($userID,$isMetric);

$obResponse -> loadRequest($className,$norm);

foreach($itemList as $obItem){

	$result = getTruckRecord($obItem -> machine,$isMetric,$norm,$obItem -> location,$obItem -> commodity);
	
	$obMachine = new Machine($className,$obItem -> machine,$obItem -> location,$obItem -> commodity,$obItem -> type,$kpiList);
	
	$obMachine -> loadData($result,$className);
	
	$obResponse -> loadData($obMachine);
}

echo json_encode($obResponse -> printStruct());

//print_r($obResponse -> printStruct());

//print_r($obResponse);

//getTruckRecord();

?>